<?php
namespace app\admin\controller;

use think\Controller;
use app\admin\model\Login;

class Base extends Controller
{
    public function _initialize()
    {
    	//TODo登录
        $data = $this->getCookie();
        if (empty($data)) {
            # code...
            $this->redirect('login/login');
        } else {
            # code...
            $res = Login::checkLogin($data);
            if (!$res) {
                # code...
                $this->redirect('login/login');
            } 
        }
        
    }

    public function setCookie($data = array())
    {
        cookie('username', $data['username']);
        cookie('uid', $data['id']);
    }

    public function getCookie()
    {
        $id = cookie('uid');
        $username = cookie('username');
        return ['id'=>$id,'username'=>$username];
    }

    public function delCookie()
    {
    	
    }
}
